package com.bdqn.zhang;

import com.bdqn.zhang.mapper.CategoryMapper;
import com.bdqn.zhang.pojo.Category;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception{
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession session=sqlSessionFactory.openSession();

        //List<Category> listCategory = session.selectList("com.bdqn.zhang.mapper.CategoryMaper.listCategory");
        //List<Category> listCategory = session.selectList("listCategory");
        List<Category> categories = session.getMapper(CategoryMapper.class).listCategory();
        for (Category c : categories) {
            System.out.println(c.getName());
        }
    }

    public void m1() {
        return super.toString();
    }


    public void m2() {
        return super.toString();
    }
}
